var common = require('../../utils/common.js');
var address = require('../../utils/city.js');
// page/one/index.js
Page({
  data:{
    content: [],
    nv: [],
    px: [],
    areas:[],
    qyopen:false,
    qyshow:false,
    nzopen:false,
    pxopen:false,
    nzshow:false,
    pxshow:false,
    isfull:false,
    // cityleft: cityData.getCity(),
    citycenter: {},
    cityright: {},
    select1: '',
    select2:'',
    shownavindex:'',
    listData: [],
    latitude: '',
    longitude: '',
    page:1,//记录页数
  },

  clickItems : function () {
    console.log("测试");
    wx.navigateTo({
      url: '../roomsDetail/roomsDetail',
    })
  },


  listqy: function(e){
    if(this.data.qyopen){
      this.setData({
        qyopen:false,
        nzopen:false,
        pxopen:false,
        nzshow:true,
        pxshow:true,
        qyshow:false,
        isfull:false,
        shownavindex: 0
      })
    }else{
      this.setData({
        content:this.data.areas,
        qyopen:true,
        pxopen:false,
        nzopen:false,
        nzshow:true,
        pxshow:true,
        qyshow:false,
        isfull:true,
        shownavindex:e.currentTarget.dataset.nav
      })
    }
    
  },
  list: function(e){
    if(this.data.nzopen){
      this.setData({
        nzopen:false,
        pxopen:false,
        qyopen:false,
        nzshow:false,
        pxshow:true,
        qyshow:true,
        isfull:false,
        shownavindex: 0
      })
    }else{
      this.setData({
        content:this.data.nv,
        nzopen:true,
        pxopen:false,
        qyopen:false,
        nzshow:false,
        pxshow:true,
        qyshow:true,
        isfull:true,
        shownavindex:e.currentTarget.dataset.nav
      })
    }
  },
  listpx: function(e){
    if(this.data.pxopen){
      this.setData({
        nzopen:false,
        pxopen:false,
        qyopen:false,
        nzshow: true,
        pxshow:false,
        qyshow:true,
        isfull:false,
        shownavindex: 0
      })
    }else{
      this.setData({
        content:this.data.px,
        nzopen:false,
        pxopen:true,
        qyopen:false,
        nzshow: true,
        pxshow:false,
        qyshow:true,
        isfull:true,
        shownavindex:e.currentTarget.dataset.nav
      })
    }
    console.log(e.target)
  },
  selectleft: function(e){
    this.setData({
      cityright:{},
      citycenter:this.data.cityleft[e.currentTarget.dataset.city],
      select1: e.target.dataset.city,
      select2:''
    });
  },
  selectcenter: function(e){
    
    this.setData({
      cityright:this.data.citycenter[e.currentTarget.dataset.city],
      select2: e.target.dataset.city
    });
  },
  hidebg: function(e){
    
    this.setData({
      qyopen:false,
      nzopen:false,
      pxopen:false,
      nzshow:true,
      pxshow:true,
      qyshow:true,
      isfull:false,
      shownavindex: 0
    })
  },
  initData: function (latitude, longitude) {
    console.log('0000');
    var that = this;
    common._get('/wx/m/roomlist', { lat: latitude, lon: longitude, page: that.page},
      //成功
      function (res) {
        if (res.data.success) {
          console.log(1111);
          console.log(res.data)
          for (var i in res.data.data) {
            res.data.data[i].furniture = JSON.parse(res.data.data[i].furniture);
          }
          var datas = that.data.listData.concat(that.data.listData)
          console.log(datas)
          that.setData({
            listData: datas
          })
          that.page++;
        }
      });

      
  },
//获取位置
  initLocation: function () {
    var that = this;
    wx.getLocation({
      type: 'wgs84',
      success: function (res) {
        var latitude = res.latitude
        var longitude = res.longitude
        that.initData(latitude, longitude);
      }
    })

  },

  /**
  * 生命周期函数--监听页面加载
  */
  onLoad: function (options) {

    this.setData({
      nv: ['三房一厅', '两房一厅', '一房一厅', '单间',],
      px: ['默认排序', '离我最近', '价格最低', '价格最高']
    })
    // 默认选择南宁
    var id = address.provinces[19].id
    this.setData({
      areas: address.areas[address.citys[id][0].id],
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.initLocation();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
  
})